package com.jinxin.platform.cddjnhjcxtsysset.controller;

import com.jinxin.platform.base.api.annotation.APCOSApi;
import com.jinxin.platform.base.api.annotation.APCOSApiOperation;
import com.jinxin.platform.base.api.constant.APCOSApiConstans;
import com.jinxin.platform.base.common.pojo.JsonResult;
import com.jinxin.platform.cddjnhjcxtsysset.bean.CddjnhjcxtsyssetHomeAttach;
import com.jinxin.platform.cddjnhjcxtsysset.common.SysOrgInfo;
import com.jinxin.platform.cddjnhjcxtsysset.common.SysUserVO;
import com.jinxin.platform.cddjnhjcxtsysset.rpc.CddjnhjcxtsyssetRpc;
import com.jinxin.platform.cddjnhjcxtsysset.service.ICddjnhjcxtsyssetHomeAttachService;
import com.jinxin.platform.cddjnhjcxtsysset.utils.UploadFileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * All rights Reserved, Designed By www.beonelot.com
 *
 * @version: V1.0
 * @Copyright: www.beonelot.com Inc. All rights reserved.
 * @Description：
 * @Date: 2020-12-26
 * @Author: Lingnan
 **/
@APCOSApi(value = "首页附件相关接口", developers = {"lingnan"}, description = "首页附件相关接口")
@Api(tags = "首页附件相关接口")
@RestController
@RequestMapping("/cddjnhjcxtsysset/cddjnhjcxtsyssetHomeAttach")
@Slf4j
public class CddjnhjcxtsyssetHomeAttachController {
    @Autowired
    private ICddjnhjcxtsyssetHomeAttachService homeAttachService;
    @Autowired
    private CddjnhjcxtsyssetRpc cddjnhjcxtsyssetRpc;

    @APCOSApiOperation(value = "根据条件查询首页附件信息", developers = {"lingnan"}, description = "根据条件查询首页附件信息",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @ApiOperation(value = "根据条件查询首页附件信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="name",value="附件名称", paramType="query",dataType="String")
    })
    @GetMapping("/list")
    public JsonResult list(@RequestParam(required = false) String name){
        SysUserVO currentUser = cddjnhjcxtsyssetRpc.getCurrentUser();
        if(currentUser == null){
            return JsonResult.error("获取当前用户信息失败");
        }
        HashMap param = new HashMap();
        param.put("name", name);
        param.put("orgId", currentUser.getOrgId());
        List<CddjnhjcxtsyssetHomeAttach> list = homeAttachService.list(param);
        return JsonResult.ok("success",list);
    }

    @APCOSApiOperation(value = "上传附件", developers = {"lingnan"}, description = "上传附件",
            infType = APCOSApiConstans.INF_TYPE_OTHER, infCategory = APCOSApiConstans.INF_CATEGORY_ALL)
    @PostMapping("/uploadFiles")
    public JsonResult uploadFiles(MultipartFile file,String name) {
        return homeAttachService.uploadFile(file,name);
    }

}
